package model.util;

import javax.persistence.EntityManager;
import javax.persistence.Persistence;

/**
 * This code was taken almost in entirety from the Hibernate 3.1 
 * reference manual. The package name and formatting has been 
 * changed only.
 */
public class EntityManagerUtil
{
    private static final EntityManager entityManager;

    static
    {
        try
        {
            // Create the SessionFactory persistence.xml
        	entityManager = Persistence.createEntityManagerFactory("ScrumApp").createEntityManager();
        }
        catch (Throwable ex)
        {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial EntityManager creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static EntityManager getEntityManager()
    {
        return entityManager;
    }
}

